package com.distortiongames.level27
{
	import com.distortiongames.level27.generation.*;
	import com.distortiongames.level27.generation.random.ElementalChance;
	import com.distortiongames.level27.scenes.GameScene;
	import com.distortiongames.level27.scenes.ViewScene;
	import com.greensock.OverwriteManager;
	import com.pblabs.core.PBGroup;
	import com.pblabs.debug.Console;
	import com.pblabs.debug.ConsoleCommandManager;
	import com.pblabs.input.KeyboardManager;
	import com.pblabs.property.PropertyManager;
	import com.pblabs.time.TimeManager;
	import flash.display.*;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.*;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.sampler.NewObjectSample;
    
    
	
	/**
	 * ...
	 * @author Jefferson Wagner
	 */
	[SWF(width="800", height="600", frameRate="60",wmode="gpu", backgroundColor="#000000")]
	public class Main extends Sprite 
	{
		[Embed(source = "../../../../assets/data/keywords.xml", mimeType="application/octet-stream")]
		private var keywords:Class;
		
		public var rootGroup:PBGroup = new PBGroup();
		
		private var keywordRepository:KeywordRepository;
		
		public function Main():void 
		{
			if (stage) init();
			
			else addEventListener(Event.ADDED_TO_STAGE, init);
			processKeywords();
			//var phrase:Phrase = new Phrase(keywordRepository.shades["Ruby"], keywordRepository.primaryWords["Chosen"], keywordRepository.secondaryWords["Hopeless"], keywordRepository.tertiaryWords["Nothingness"]);
			var phrase:Phrase = new Phrase(keywordRepository.getRandomShade(), keywordRepository.getRandomPrimary(), keywordRepository.getRandomSecondary(), keywordRepository.getRandomTertiary());
			var gen:Generator = new Generator(phrase, 200, 200);
			var map:Map = gen.generate(true);
			//trace(map);
			
			OverwriteManager.init(OverwriteManager.NONE);

            // Set the stage to resize properly.
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            
            // Set up the root group for the demo and register a few useful
            // managers. Managers are available via dependency injection to the
            // demo scenes and objects.
            rootGroup.initialize();
            rootGroup.name = "Level27SceneGroup";
            rootGroup.registerManager(Sprite, this);
			rootGroup.registerManager(Stage, stage);
			rootGroup.registerManager(Generator, gen);
            rootGroup.registerManager(PropertyManager, new PropertyManager());
            rootGroup.registerManager(ConsoleCommandManager, new ConsoleCommandManager());
            rootGroup.registerManager(TimeManager, new TimeManager());
            rootGroup.registerManager(KeyboardManager, new KeyboardManager());
            rootGroup.registerManager(Console, new Console());
			
			var scene:PBGroup = new ViewScene();
			scene.owningGroup = rootGroup;
			scene.initialize();
			
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function processKeywords() : void {
			var xml:XML = new XML(new keywords);
			keywordRepository = new KeywordRepository(xml);
			//trace(xml);
		}
		
	}
	
}